<template>
	<view>
		<baseHead title="企业相册" bg="#ffffff" color="#000000" :text_right="title" :right="true" @clickRight="clickRight">
		</baseHead>

		<view class="sdgt">
			<u-upload :fileList="fileList5" @afterRead="afterRead" @delete="deletePic" name="5" :previewFullImage="true"
				:disabled="!show" :uploadIconColor="uploadIconColor" :deletable="show" previewImage>
			</u-upload>
		</view>
	</view>
</template>

<script>
	import baseHead from '@/pages/component/baseHead.vue'
	export default {
		data() {
			return {
				URL: this.$config.domain.staticUrl,
				headImg: [],
				model: {
					PhotoPaths: "",
				},
				show: true,
				title: "保存",
				uploadIconColor: '#D3D4D6'
			}
		},
		components: {
			baseHead
		},
		onLoad(option) {
			console.log(option);
			if (option.type) {
				this.show = false
				this.title = ''
				this.uploadIconColor = "#f7f7f7"
			} else {
				this.show = true
				this.title = '保存'
			}
		},
		computed: {
			fileList5() {
				return this.headImg.map(res => {
					return {
						url: this.URL + res
					}
				})
			}
		},
		created() {
			this.listdata();
		},
		methods: {
			listdata() {
				let qyid = uni.getStorageSync('dianjiqiye');
				this.$http.core.tenantgetall(qyid.Id).then(res => {
					if (res.Success) {
						console.log(res);
						this.model = res.Result;
						this.headImg = JSON.parse(res.Result.PhotoPaths);
						console.log(this.headImg);
					}
				})
			},
			clickRight() {
				console.log(this.model)
				this.model.PhotoPaths = JSON.stringify(this.headImg)
				//修改
				this.$http.core.tenantupdate(this.model).then(res => {
					console.log(res);
					if (res.Success) {
						this.$util.toast("修改成功")
						setTimeout(() => {
							uni.navigateBack();
						}, 1000)
					}
				})
			},
			// 上传 图片
			afterRead(file, lists, name) {
				var that = this;
				let tempFilePaths = file.file
				let obj = {
					src: tempFilePaths.url
				}
				that.$util.AuploadFile(obj).then(res => {
					if (res.Success) {
						console.log(res.Result);
						// that.src = res.Result.Path;
						that.headImg.push(res.Result.Path);
					}
				})
				
				// uni.uploadFile({
				// 	url: this.$config.domain.baseUrl + "/api/core/file/upload",
				// 	filePath: tempFilePaths.url,
				// 	name: "file",
				// 	header: {
				// 		'Authorization': uni.getStorageSync("access_token").token_type + " " +
				// 			uni.getStorageSync("access_token").access_token,
				// 	},
				// 	success: function(res) {
				// 		if (res.statusCode == 200) {
				// 			let data = JSON.parse(res.data)
				// 			if (data.Success) {
				// 				console.log(data.Result.Path)
				// 				console.log(data.Result);
				// 				that.headImg.push(data.Result.Path);
				// 			}
				// 		}
				// 	}
				// })
			},
			// 删除图片
			deletePic(file, lists, name) {
				console.log(file)
				this.headImg.splice(file.index, 1)
			}
		}
	}
</script>

<style scoped lang="scss">
	.sdgt {
		display: flex;
		// justify-content: left;
		align-items: center;
		flex-wrap: wrap;
		padding: 10rpx;
	}

	/deep/.u-upload__wrap__preview {
		margin: 10rpx !important;
	}
	/deep/.u-upload__wrap{
		justify-content: left;
	}
</style>